﻿@using Board.Models
@{
    Layout = null;
}


<div class="post-back-message">@ViewBag.Message</div>

@using (Html.BeginForm("UserSave", "Account", FormMethod.Post, new {@id = "UserForm", @class = "jquery-form"}))
{

    if (ViewBag.User != null && ViewBag.Success != null)
    {
        WebUser user = (WebUser) ViewBag.User;
        bool success = (bool)ViewBag.Success;
        <text>
            <div id="UserInfoDiv">
                <fieldset>
                    <legend>t_UserProfile</legend>


                
                    @Html.Hidden("UserId", user.UserId)

                    <div class="display-label">
                        Username
                    </div>
                    <div class="display-field">
                        @if (success)
                        {
                            @user.Username
                        }
                        else
                        {
                            @Html.TextBox("Username", user.Username)
                        }
                    </div>
                
                    <div class="display-label">
                        Password
                    </div>
                    <div class="display-field">
                        @if (!success)
                        {
                            @Html.Password("Password")
                        }
                    </div>

                    <div class="display-label">
                        First Name
                    </div>
                    <div class="display-field">
                        @if (success)
                        {
                            @user.FirstName
                        }
                        else
                        {
                            @Html.TextBox("FirstName", user.FirstName)
                        }
                    </div>

                    <div class="display-label">
                        Last Name
                    </div>
                    <div class="display-field">
                        @if (success)
                        {
                            @user.LastName
                        }
                        else
                        {
                            @Html.TextBox("LastName", user.LastName)
                        }
                    </div>

                    <div class="display-label">
                        User Type
                    </div>
                    <div class="display-field">
                        @if (ViewBag.UserTypeDropdown == null)
                        {
                            @Html.TextBox("UserType", user.UserType)
                        }
                        else
                        {
                            @Html.DropDownList("UserType", (IEnumerable<SelectListItem>) ViewBag.UserTypeDropdown)
                        }
                    
                    </div>


                    <div class="display-label">
                        Show All Beds<br />in one screen
                    </div>
                    <div class="display-field">
                        @if (success)
                        {
                            @user.ShowAllBed.ToString()
                        }
                        else
                        {
                            <input id="ShowAllBed" name="ShowAllBed" type="checkbox" value="@user.ShowAllBed.ToString()"/>
                        }
                    </div>

                    <div class="display-label">
                        Default Site
                    </div>
                    <div class="display-field">
                        @if (ViewBag.DefaultSiteDropdown == null)
                        {
                            <text>
                                @(user.DefaultSite != null ? user.DefaultSite.SiteId : "")
                            </text>
                        }
                        else
                        {
                            <text>
                                @Html.DropDownList("DefaultSite", (IEnumerable<SelectListItem>) ViewBag.DefaultSiteDropdown)
                            </text>
                        }
                    </div>

                    <div class="display-label">
                        Default Unit
                    </div>
                    <div class="display-field">
                        @if (ViewBag.DefaultUnitDropdown == null)
                        {
                            <text>
                                @(user.DefaultUnit != null ? user.DefaultUnit.UnitId : "")
                            </text>
                        }
                        else
                        {
                            <text>
                                @Html.DropDownList("DefaultUnit", (IEnumerable<SelectListItem>) ViewBag.DefaultUnitDropdown)
                            </text>
                        }
                    </div>
                    <div class="display-label">
                        User Role
                    </div>
                    <div class="display-field">
                        @Html.DropDownList("Roles", (IEnumerable<SelectListItem>) ViewBag.RoleDropdown, new {multiple = "multiple"})
                    </div>
                </fieldset>
            </div>
            @if (!success)
            {
                <p>
                    <input type="submit" value="Save" />
                </p>
            }
            <p>
                @Html.ActionLink("Back to List", "UserList")
            </p>
            <script>
                updateJqueryForm();
            </script>
        </text>
    }


}
